package com.peng.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    //建议采用2.5.6的spring boot版本
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }

    @Bean
    public Docket docket(Environment environment){

        boolean dev = environment.acceptsProfiles("dev");

        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("Kuangshen")
                .enable(dev)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.peng.controller"))
                // 配置如何通过path过滤,即这里只扫描请求以/kuang开头的接口
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    public ApiInfo apiInfo(){
        return new ApiInfo("狂的API文档",
                "你好blue", "v1.0",
                "https://www.baidu.com", new Contact("邓鹏", "https://www.baidu.com", ""),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList());

    }
}
